//引入请求接口
import {reqAddress,reqTrade,reqSumbitOrder} from '@/api/'
export default {
    state: () => ({
        address:[],
        trades:{},
        
    }),
    mutations:{
        GETADDRESS(state,data){
            state.address=data
        },
        GETTRAGE(state,data){
            state.trades=data
        }
    },
    actions: {
        async getAddress({commit}){
            const s=  await reqAddress()
            if(s.code===200){
                commit("GETADDRESS",s.data) 
            }
        },
        async getTrade({commit}){
            const s=  await reqTrade()
            if(s.code===200){
                commit("GETTRAGE",s.data) 
            }
        },
        async sumbmit({},data){
            try{
                const s=  await reqSumbitOrder(data.traderNo,data.other)
                if(s.code===200){
                    return s.data
                }else{
                    return Promise.reject(new Error(s.message))
                }
            }catch(error){
                return Promise.reject('fail') 
            }
            
        }
    }
}